import {listByDictionaryCode} from "@/api/sys/dictionaryApi";
import formOption from "@/option/start/formEngine/formOption"
import {getById, list} from "@/api/start/formEngine/formApi";
import {systemDictionary} from "@/const/systemConstant";

export default {
    inject: ['bpmnModeler'],
    props: {
        element: Object,

    },
    computed: {
        systemDictionary() {
            return systemDictionary;
        },
        formTypeCode() {
            return "activiti_form_types"
        },
        formTypeProps() {
            return {
                label: "name",
                value: "dictionaryValue"
            }
        },
        activitiAssigneeTypeProps() {
            return {
                label: "name",
                value: "dictionaryValue"
            }
        },

        formTypeSystemFormColumn() {
            return {
                children: formOption()
            };
        },
        formTypeSystemFormProps() {
            return {
                label: 'name',
                value: 'id'
            }
        }
    },
    data() {
        return {
            formTypeDic: [],
            activitiAssigneeTypeDic: [],
        }
    },
    created() {
        this.initData();
        const bpmnModeler = this.bpmnModeler();
        this.modeling = bpmnModeler.get('modeling');
    },
    methods: {
        formTypeSystemFormFormatter(row) {
            if (!row) return null;
            return row.name;
        },
        initData() {
            if (this.formTypeCode) {
                listByDictionaryCode(this.formTypeCode).then(res => {
                    this.formTypeDic = res.data.data;
                })
            }
            if (this.activitiAssigneeTypeCode) {
                listByDictionaryCode(this.activitiAssigneeTypeCode).then(res => {
                    this.activitiAssigneeTypeDic = res.data.data;
                })
            }
        },
        formTypeSystemFormLoad({page, value, data}, callback) {
            if (value) {
                getById(value).then(res => callback(res.data.data))
                return
            }
            let pageParams = {}
            let formSearchParams = data;
            pageParams.current = page.currentPage
            pageParams.size = page.pageSize;
            let searchParams = {};
            const requestData = Object.assign(pageParams, formSearchParams, searchParams)
            list(requestData).then(res => {
                let resultData = res.data.data;
                callback({
                    data: resultData.records,
                    total: resultData.total
                })
            })

        }
    }
}

